package main

import (
	"github.com/gin-gonic/gin"
	"html/template"
	"net/http"
)

func main(){
	r := gin.Default()

	// gin框架中给模板添加自定义函数
	r.SetFuncMap(template.FuncMap{
		"safe": func(str string) template.HTML{
			return template.HTML(str)
		},
	})

	//模板解析
	//r.LoadHTMLFiles("templates/index.tmpl")
	r.LoadHTMLGlob("templates/**/*")

	r.GET("/index", func(c *gin.Context) {
		//模板渲染
		c.HTML(http.StatusOK, "index.tmpl", gin.H{
			"title": "liuck.com",
		})
	})

	r.GET("/posts/index", func(c *gin.Context) {
		//模板渲染
		c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{
			"title": "posts_liuck.com",
		})
	})


	r.GET("/users/index", func(c *gin.Context) {
		//模板渲染
		c.HTML(http.StatusOK, "users/index.tmpl", gin.H{
			"title": "<a href='https://liwenzhou.com'>李文周的博客</a>",
		})

	})

	//启动
	r.Run(":9090")
}
